import myAxios from "@/request";

// 定义用户注册请求的接口类型
interface UserRegisterRequest {
  username: string;
  password: string;
}

// 定义用户登录请求的接口类型
interface UserLoginRequest {
  username: string;
  password: string;
}

// 定义获取当前用户请求的接口类型
/**
 *
 */
interface GetCurrentUserRequest {
  // 根据实际情况添加必要的参数
  username: string;
}

// 定义搜索用户请求的接口类型
interface SearchUsersRequest {
  username: string;
}

// 定义删除用户请求的接口类型
interface DeleteUserRequest {
  id: number | string;
}

/**
 * 用户注册
 * @param params
 */
export const userRegister = async (params: UserRegisterRequest) => {
  return await myAxios.request({
    url: "/api/user/register",
    method: "POST",
    data: params,
  });
};

/**
 * 用户登录
 * @param params
 */
export const userLogin = async (params: UserLoginRequest) => {
  return await myAxios.request({
    url: "/api/user/login",
    method: "POST",
    data: params,
  });
};

/**
 * 用户注销
 * @param params
 */
export const userLogout = async (params: any) => {
  return await myAxios.request({
    url: "/api/user/logout",
    method: "POST",
    data: params,
  });
};

/**
 * 获取当前用户
 * @param params
 */
export const getCurrentUser = async (params: GetCurrentUserRequest) => {
  return await myAxios.request({
    url: "/api/user/current",
    method: "GET",
    params,
  });
};

/**
 * 获取用户列表
 * @param params
 */
export const searchUsers = async (params: SearchUsersRequest) => {
  return await myAxios.request({
    url: "/api/user/list", // 修改为正确的接口路径
    method: "POST",
    data: params,
  });
};

/**
 * 删除用户
 * @param id
 */
export const deleteUser = async (id: DeleteUserRequest["id"]) => {
  return await myAxios.request({
    url: "/api/user/delete", // 修改为正确的接口路径
    method: "POST",
    data: { id },
    headers: {
      "Content-Type": "application/json",
    },
  });
};
